package com.superdry.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.drysurper.R;
import com.superdry.adapter.CityListAdapter.ViewHolder;
import com.superdry.json.Coupon;
import com.superdry.json.Location;

public class CouponAdapter extends BaseAdapter {

	public List<Coupon> coupons;
	public Context mContext;

	public CouponAdapter(List<Coupon> coupons, Context mContext) {

		this.coupons = coupons;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		return coupons.size();
	}

	@Override
	public Coupon getItem(int position) {
		return coupons.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {

		ViewHolder viewHolder;
		final Coupon item = getItem(position);
		if (view == null) {
			viewHolder = new ViewHolder();
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.item_coupon, parent, false);
			viewHolder.money = (TextView) view.findViewById(R.id.money);
			viewHolder.integral = (TextView) view.findViewById(R.id.validity_coupon);
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		viewHolder.money.setText(item.getCouponPrice() + "");
		viewHolder.integral.setText(item.getCouponTitle() + "\n" + "满" + item.getCouponID() + "元可用\n" + "有效期"+item.getValidDate());

		return view;
	}

	public static class ViewHolder {

		public TextView money;
		public TextView integral;
	}
}
